package com.xy.frame.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xy.frame.IConstants;
import com.xy.frame.model.AjaxJson;
import com.xy.frame.model.SessionUser;
import com.xy.frame.service.MenuService;

/**
 * @author Administrator
 * 框架页面相关请求
 */
@Controller
@RequestMapping("/frame")
public class FrameController {

	Logger logger = LoggerFactory.getLogger(FrameController.class);
	@Autowired
	MenuService menuService;

	@RequestMapping(value = "/select", method = RequestMethod.GET)
	public String select() {
		if (logger.isDebugEnabled()) {
			logger.debug("请求【/select】响应页面【/view/index/select.jsp】");
		}
		return "index/select";
	}

	@RequestMapping(value = "/jump", method = RequestMethod.GET)
	public String jumpFrame() {
		if (logger.isDebugEnabled()) {
			logger.debug("请求【/frame/jump】响应页面【/view/jump/frame.jsp】");
		}
		return "jump/frame";
	}
    @RequestMapping(value = "/metro", method = RequestMethod.GET)
    public String metroFrame() {
        if (logger.isDebugEnabled()) {
            logger.debug("请求【/frame/metro】响应页面【/view/metro/frame.jsp】");
        }
        return "metro/frame";
    }
    @RequestMapping(value = "/mac", method = RequestMethod.GET)
    public String macFrame() {
        if (logger.isDebugEnabled()) {
            logger.debug("请求【/frame/mac】响应页面【/view/mac/frame.jsp】");
        }
        return "mac/frame";
    }
	/**
	 * 获取当前用户菜单
	 * @param session
	 * @return
	 */
	@RequestMapping(value = "/getUserMenu", method = RequestMethod.GET)
	@ResponseBody
	public AjaxJson getUserMenu(HttpSession session) {
		AjaxJson j = new AjaxJson();
		if (logger.isDebugEnabled()) {
			logger.debug("请求【/frame/getUserMenu】响应【json数据】");
		}
		SessionUser userBean = (SessionUser)session.getAttribute(IConstants.SESSION_USER);
		// sysadmin(系统配置) 或者 sysadmin 角色组用户加载所有菜单 
		if(userBean.getLoginName().equals("sysadmin")){
			//加载所有菜单
			List<Map<String, Object>> menuTree = menuService.loadMenuTree();
			j.setObj(menuTree);
		}else{
			//加载 当前用户权限菜单
		}
		return j;
	}
}